package com.lazycat.backend.service.impl.shop;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lazycat.backend.mapper.GoodMapper;
import com.lazycat.backend.pojo.Good;
import com.lazycat.backend.service.shop.FetchGoodTypesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;

@Service
public class FetchGoodTypesServiceImpl implements FetchGoodTypesService {
    @Autowired
    private GoodMapper goodMapper;

    @Override
    public JSONObject fetch() {
        HashSet<String> types = new HashSet<>();
        List<Good> goods = goodMapper.selectList(null);
        for (Good good : goods) {
            types.add(good.getGoodType());
        }
        JSONObject resp = new JSONObject();
        resp.put("types", types);
        resp.put("error_message", "success");
        return resp;
    }
}
